package org.neframework.webtest.action.frame;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.base.BaseController;
import org.neframework.webtest.model.t_fk_role;
import org.neframework.webtest.model.t_fk_user;
import org.neframework.webtest.model.t_s_system;
import org.neframework.webtest.service.AuthService;
import org.neframework.webtest.service.VerifyService;
import org.neframework.webtest.util.tree.TreeTools;
import org.neframework.webtest.util.web.session.SessionTools;

import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;

@Controller
@RequestMapping("/cp/frame")
public class FrameController extends BaseController {

	private static AuthService authService = new AuthService();
	private static VerifyService verifyService = new VerifyService();

	@RequestMapping("/frame")
	public String frame() {

		t_s_system verify = verifyService.selectVerifyInfo();
		if (verify.getEnddate().getTime() < System.currentTimeMillis()) {
			verify.setStatus_verify("已过期");
			oc.updateObj(verify);
			return "redirect:/verify_form.htm";
		}

		logger.info("访问frame");

		return "/jsp/frame/frame.jsp";
	}

	@RequestMapping("/header")
	public String header() {

		logger.info("访问header");

		return "/jsp/frame/header.jsp";
	}

	@RequestMapping("/left_data")
	@ResponseBody
	public String left_data() {

		t_fk_user admin = SessionTools.getCurrentLoginAdmin(req);
		t_fk_role role = (t_fk_role) oc.findObjById(admin.getRole_id(),
				t_fk_role.class);

		List<Map<String, Object>> list = null;
		if (role == null) {
			list = authService.selectMenuAuthList("cp系统");
		} else {
			list = authService.selectMenuAuthList("cp系统", role.getAuth_codes());
		}

		return TreeTools.turnListToTree(list);
	}

	@RequestMapping("/main")
	public String main() {
		// TODO main 主页面
		logger.info("访问main");

		return "/jsp/frame/main.jsp";
	}

}
